<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>表单</title>
  <link rel="stylesheet" href="${ctx}/static/admin/layui/css/layui.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/formSelects-v4.css">
  </head>
<script>

</script>
  <body>
  	<div class="layui-card-body">
  	<form class="layui-form layui-form-pane">
	  <input name="calculate.id" type="hidden" value="${item.id! }" />
	  <div class="layui-row">
		  <div class="layui-col-xs12">
			  <div class="layui-form-item">
				  <label class="layui-form-label">表单属性</label>
				  <div class="layui-input-block">
					  <input type="text" readonly="readonly" autocomplete="off" class="layui-input" value="${column.column_comment!}">
				  </div>
			  </div>
		  </div>
	  </div>
	  <div class="layui-row">
	    <div class="layui-col-xs12">
	      <div class="layui-form-item layui-form-text">
	        <label class="layui-form-label">计算公式<font style="color: red">*</font></label>
	        <div class="layui-input-block">
				<textarea id="calculateid" name="calculate.calculate" placeholder="请输入计算公式" class="layui-textarea">${item.calculate!}</textarea>
		    </div>
	      </div>
	    </div>
	  </div>
	<div class="layui-row">
		<div class="layui-col-xs6">
			<table id="calculatetable" lay-filter="calculate"></table>
		</div>
		<div class="layui-col-xs6">
			<br/>
			<div class="layui-row">
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name="(" value="("/>
					</div>
				</div>
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name=")" value=")"/>
					</div>
				</div>
			</div>
			<div class="layui-row">
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name="+" value="+"/>
					</div>
				</div>
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name="-" value="-"/>
					</div>
				</div>
			</div>
			<div class="layui-row">
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name="*" value="×"/>
					</div>
				</div>
				<div class="layui-col-xs6">
					<div class="layui-input-block">
						<input type="button" class="layui-btn layui-btn-normal layui-btn-sm method" name="/" value="÷"/>
					</div>
				</div>
			</div>
		</div>
	</div>
   	  <div class="layui-form-item" style="display: none">
     	<div class="layui-input-block">
       	  <button id="submit-btn" class="layui-btn" lay-submit >立即提交</button>
          <button id="reset-btn" type="reset" class="layui-btn layui-btn-primary">重置</button>
   	    </div>
   	  </div>
	</form>
	</div>
  </body>
</html>
<script src="${ctx}/static/admin/layui/layui.js"></script>
<script src="${ctx}/static/admin/js/common.js"></script>
<script>
    var tableIns, table, params, $, ai = 0;
    layui.use(['jquery','form','table',], function(){
        $ = jQuery = layui.$;
        var form = layui.form;

        var caltable = layui.table;

        tableIns = caltable.render({
            elem: '#calculatetable',
            height:'full-255',
            size:'sm',
            url: '${ctx}/sys_admin/calculate/getCaledColumnList?moduleid=${column.moduleid!}&columnid=${column.id!}',
            even: true,
            cols: [[
                {type: 'numbers',fixed: 'left'},
                {field: 'id', title: 'ID',fixed: 'left', align:'center',width:180, hide:true},
                {field: 'column_name', title: '字段标识', align:'center'},
                {field: 'column_comment', title: '字段名称', align:'center',width:200}
            ]]
        });

        //监听行单击事件（双击事件为：rowDouble）
        caltable.on('rowDouble(calculate)', function(obj){
            var data = obj.data;

            $('#calculateid').val($('#calculateid').val() + data.column_name + ' ');

            //标注选中样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });

        $(".method").each(function() {
            $(this).bind("click",function(){
                $('#calculateid').val($('#calculateid').val() + this.name + ' ');
            })
        });

        form.on('submit', function(data){
            $.post('${ctx}/sys_admin/calculate/save', $(data.form).serialize(), function(result) {
                if (result.success) {
                    if (params.name == undefined) {
                        table.reload({});
                    } else {
                        table.reload({
                            where:{
                                name : params.name,
                                status : params.status
                            },
                            page: {
                                curr: params.curr
                            }
                        });
                    }
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    layer.msg(result.msg);
                }
            }, 'json');
            return false;
        });

    });
</script>
